<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <button onclick="addArea()">添加区要素</button>
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", "xzd_area", {

        })
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        function addArea() {
            /* 1、要素 new Zondy.Object.Feature */
            /* 2、创建要素集 new Zondy.Object.FeatureSet  addFeature */
            /* 3、调用中地服务 
            new Zondy.Server.EditDocFeature
             */
            var pointObj = new Array();
            pointObj[0] = new Zondy.Object.Point2D(114.30, 30.50);
            pointObj[1] = new Zondy.Object.Point2D(116, 30.50);
            pointObj[2] = new Zondy.Object.Point2D(116, 28);
            pointObj[3] = new Zondy.Object.Point2D(114.30, 28);
            //设置区要素的几何信息
            var gArc = new Zondy.Object.Arc(pointObj);
            //构成区要素折线
            var gAnyLine = new Zondy.Object.AnyLine([gArc]);
            //构成区要素
            var gRegion = new Zondy.Object.GRegion([gAnyLine]);
            //构成区要素的几何信息
            var fGeom = new Zondy.Object.FeatureGeometry({ RegGeom: [gRegion] });
            var cRegionInfo = new Zondy.Object.CRegionInfo({
                EndColor: 1,
                FillColor: 40, //填充色
                FillMode: 0,
                OutPenWidth: 1,
                OverMethod: 0,
                PatAngle: 1,
                PatColor: 1,
                PatHeight: 1,
                PatID: 0, //图案编号
                PatWidth: 1
            });
            //要素图形参数信息
            var graphicInfo = new Zondy.Object.WebGraphicsInfo({
                InfoType: 3,
                RegInfo: cRegionInfo
            });
            /* 属性 */
            //设置区要素的属性信息
            var attValue = ["webgis"];
            //创建一个新的区要素
            var newFeature = new Zondy.Object.Feature({ AttValue: attValue, fGeom: fGeom, GraphicInfo: graphicInfo });
            newFeature.setFType(3);
            /* 要素集 */
            //创建一个要素数据集
            var featureSet = new Zondy.Object.FeatureSet();
            var fldNumber = 1;
            var fldType = ["string"];
            var fldName = ["name"];
            var cAttValue = new Zondy.Object.CAttStruct({
                FldNumber: fldNumber,
                FldType: fldType,
                FldName: fldName
            });
            featureSet.AttStruct = cAttValue;
            featureSet.addFeature(newFeature);
            /* 服务 */
            var editDocFeature = new Zondy.Service.EditDocFeature("xzd_area", 0, {

            });
            editDocFeature.add(featureSet, onPloySuccess);
        }
        function onPloySuccess(data) {
            if (data.succeed) {
                alert("添加区要素成功！");
                docLayer.refresh();
            } else {
                alert("添加区要素失败！");
            }
        }
        /* 自己尝试封装区 */
    </script>
</body>

</html>